package com.ruoyi.zyx.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxWarn;
import com.ruoyi.zyx.service.IZyxWarnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提醒信息Controller
 *
 * @author lhs
 * @date 2021-06-03
 */
@RestController
@RequestMapping("/zyx/warn")
public class ZyxWarnController extends BaseController
{
    @Autowired
    private IZyxWarnService zyxWarnService;

    /**
     * 查询提醒信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ZyxWarn zyxWarn)
    {
        startPage();
        List<ZyxWarn> list = zyxWarnService.selectZyxWarnList(zyxWarn);
        return getDataTable(list);
    }

    /**
     * 导出提醒信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:warn:export')")
    @Log(title = "提醒信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxWarn zyxWarn)
    {
        List<ZyxWarn> list = zyxWarnService.selectZyxWarnList(zyxWarn);
        ExcelUtil<ZyxWarn> util = new ExcelUtil<ZyxWarn>(ZyxWarn.class);
        return util.exportExcel(list, "提醒信息数据");
    }

    /**
     * 获取提醒信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:warn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxWarnService.selectZyxWarnById(id));
    }

    /**
     * 获取提醒信息条数
     * @return
     */
    @GetMapping(value = "/getMyWarnNum/")
    public AjaxResult getMyWarnNum()
    {
       Long deptid= SecurityUtils.getLoginUser().getUser().getDeptId();
        return AjaxResult.success(zyxWarnService.getMyWarnNum(deptid));
    }
    /**
     * 修改提醒信息
     */
    @Log(title = "提醒信息", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/updMyWarnRead/{id}")
    public AjaxResult updMyWarnRead(@PathVariable("id") Long id)
    {
//        Long deptid= SecurityUtils.getLoginUser().getUser().getDeptId();
        return toAjax(zyxWarnService.updMyWarnRead(id));
    }
    /**
     * 新增提醒信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:warn:add')")
    @Log(title = "提醒信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxWarn zyxWarn)
    {
        return toAjax(zyxWarnService.insertZyxWarn(zyxWarn));
    }

    /**
     * 修改提醒信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:warn:edit')")
    @Log(title = "提醒信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxWarn zyxWarn)
    {
        return toAjax(zyxWarnService.updateZyxWarn(zyxWarn));
    }

    /**
     * 删除提醒信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:warn:remove')")
    @Log(title = "提醒信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxWarnService.deleteZyxWarnByIds(ids));
    }
}
